package day11.file;

import java.io.File;

/**
 * @author Xiao
 * @date 2021/7/31
 */
public class FileCase02 {
    /**
     * 3.统计当前文件下有多少个java文件
     */
    public static void main(String[] args) {
        File dirModule = new File("videoPractice");
        int count = countJava(dirModule);
//        System.out.println(Arrays.toString(dirModule));
        System.out.println("count:" + count);

    }

    private static int countJava(File dir) {
        File[] dirs = dir.listFiles();
        int count = 0;
        if (dirs != null) {
            for (File file : dirs) {
                if (file.isFile()) {
                    if (file.getName().endsWith(".java")) {
                        count++;
                    }
                } else {
                count += countJava(file);
                }
            }
        }
        return count;
    }
}
